<template>
    <div>
        病房号：
        <input type="text" v-model="ps.name">
        所属科室：
         <select name="" v-model="ps.ks" id="">
                            <option value="">请选择</option>
                            <option value="内科">内科</option>
                            <option value="外科">外科</option>
                            <option value="心肺科">心肺科</option>
                            <option value="脑科">脑科</option>
                        </select>
                        <input type="button" value="查询" @click="getdata">
        <table>
            <thead>
                <tr>
                    <input type="checkbox" name="" v-model="all" @change="allin" id="">
                    <td>病房号</td>
                    <td>所属科室</td>
                    <td>床位数</td>
                    <td>状态</td>
                    <td>空床位</td>
                    <td>创建时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data" :key="a.Bid">
                    <td><input type="checkbox" name="" :value="a.Bid" v-model="query" id=""></td>
                    <td>{{a.Name}}</td>
                    <td>{{a.KS}}</td>
                    <td>{{a.Num}}</td>
                    <td>{{a.State?"住满":"未住满"}}</td>
                    <td>{{a.CW}}</td>
                    <td>{{moment(a.createtime).format("YYYY-MM-DD")}}</td>
                    <td>
                        <input type="button" value="删除" @click="del(a.Bid)">
                        <input type="button" value="修改" @click="xq(a.Bid)">
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="批量删除" @click="dels">
        <input type="button" value="批量满房" @click="states">
        <input type="button" value="批量未满" @click="upd">
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

onMounted(()=>{
    getdata();
})

let data=ref([
    {
    "Bid": 0,
    "Name": "string",
    "KS": "string",
    "Num": "string",
    "State": true,
    "CW": "string",
    "createtime": "2025-10-11T05:21:12.108Z"
  }
])

const ps=ref({
    name:"",
    ks:"",
})
const query = ref([]);
const all = ref(false);
const allin=(val)=>{
    query.value = [];
    if(all.value){
        data.value.forEach((a)=>{
            query.value.push(a.Bid);
        })
    }
}


const getdata=()=>{
    axios.get("https://localhost:7168/api/BF/GetAll",{params:ps.value}).then((res)=>{
        data.value = res.data;
    })
}

const del=(id)=>{
    if(!confirm("确认删除吗")){
        return;
    }
    axios.delete("https://localhost:7168/api/BF/Del",{params:{id:id}}).then((res)=>{
        if(res.data>0){
            alert("删除成功");
            getdata();
        }
        else{
            alert("删除失败");
        }
    })
}
const dels=(id:any)=>{
     if(!confirm("确认删除吗")){
        return;
    }
    axios.delete("https://localhost:7168/api/BF/Del",{params:{id:query.value.toString()}}).then((res)=>{
        if(res.data>0){
            alert("删除成功");
            getdata();
        }
        else{
            alert("删除失败");
        }
    })
}
const states=(val:any)=>{
    if(!confirm("确定修改吗?")){
        return;
    }
    axios.get("https://localhost:7168/api/BF/setok",{params:{id:query.value.toString()}}).then((res)=>{
           if(res.data > 0){
            alert("修改成功");
            
            getdata();
        }else{
            alert("修改失败");
        }
    })
}
const upd = (val:any)=>{
     if(!confirm("确定修改吗?")){0
        return;
    }
    axios.get("https://localhost:7168/api/BF/setno",{params:{id:query.value.toString()}}).then((res)=>{
           if(res.data > 0){
            alert("修改成功");
          
            getdata();
        }else{
            alert("修改失败");
        }
    })
}
const xq=(id:any)=>{
    router.push({path:"/Update",query:{id:id}});
}
</script>

<style scoped>

</style>